package com.around.test.m3u8.util;

import com.google.common.collect.Lists;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Title:
 * @Description:
 * @Company:
 * @Author: moodincode
 * @Create: Date:2021年02月26日
 */
public class MergeTxt {
    public static void main(String[] args) throws Exception {
        File file=new File("G:\\test\\tp\\n\\test.txt");
        Set<String> urls=new HashSet<>();
        if(file.exists()&&file.isFile()){
            BufferedReader br=new BufferedReader(new FileReader(file));
            String s = null;
            while((s = br.readLine())!=null){//使用readLine方法，一次读一行
                System.out.println(s);
                s=s.split("\\?")[0];
                urls.add(s);
            }
            br.close();;
        }
        if(urls.size()>0){
            File file2=new File("G:\\test\\tp\\n\\test2.txt");
            BufferedWriter bw=new BufferedWriter(new FileWriter(file2));
            List<String> tps= Lists.newArrayList(urls);
            for (int i = 0; i < tps.size(); i++) {
                bw.write(tps.get(i)+"?t="+i);
                bw.newLine();

            }
            bw.flush();
            bw.close();

        }
    }
}
